#ifndef SBUF_H_
#define SBUF_H_

typedef struct {
	int *buf;	/* Buffer array */
	int n;		/* Maximun number of slots */
	int front;	/* buf[(front+1)%n] is first item */
	int rear;	/* buf[rear%n] is last item */
	sem_t mutex; /* Protects accesses to buf */
	sem_t slots; /* Counts available slots */
	sem_t items; /* counts available items */
} sbuf_t;

void sbuf_init(sbuf_t *sp, int n);
void sbuf_insert(sbuf_t *sp, int item);
int sbuf_remove(sbuf_t *sp);

#endif /*SBUF_H_*/
